<?php

class LocaleTopMerchandise extends Zend_Db_Table_Abstract
{
    protected $_name = 'locale_top_merchandise';
	
    public function setTopMerchandiseForLocale( $items, $locale_id )
    {
    	$results = array();
		
		if(!isset($locale_id) || !isset($items))
		{
			$results['status'] = "FAILED_BAD_PARAM";
			return $results;
		}
		
		try
		{
	        $this->delete("locale_id=$locale_id");
	
			$rows_affected = 0;
			foreach( $items as $item )
				$rows_affected += $this->insert( $item );
			$results['status'] = "SUCCEEDED";
			$results['rows_affected'] = $rows_affected;
		}
		catch(Exception $e)
		{
			$results['status'] = "FAILED";
			$results['reason'] = "".$e;
		}
		
        return $results;
    }

    public function getTopMerchandiseForLocale( $locale_id )
    {
    	$results = array();
		
		if(!isset($locale_id))
		{
			$results['status'] = "FAILED_BAD_PARAM";
			return $results;
		}
		
		try
		{
			$rows = array();
			
	        $r = $this->fetchAll("locale_id=$locale_id");
			if($r)
			{
				foreach( $r as $fetchedRow )
					$rows[] = $fetchedRow->toArray();
			}
			
			$results['status'] = "SUCCEEDED";
			$results['rows'] = $rows;
		}
		catch(Exception $e)
		{
			$results['status'] = "FAILED";
			$results['reason'] = "".$e;
		}
		
		return $results;
    }
}

?>
